/* Thumbs.java Copyright 2010 by Jo Pol
 *
 * This file is part of fs-thumbs.
 *
 * fs-thumbs  is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * fs-thumbs  is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with BobbinWork.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.fs_thumbs;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.MessageFormat;

import com.googlecode.fs_thumbs.FsCollection.FsException;
import com.googlecode.fs_thumbs.FsCollection.Waypoint;

public class SinglePage extends Main {

	public SinglePage(String[] args, FsCollection fsCollection) //
			throws FileNotFoundException, IOException, FsException, FsException, FsException {
		super(args);
		System.out.println(String.format(detailHead, htmlTitle(fsCollection)));
		printNode(fsCollection);
		System.out.println(MessageFormat.format(mainFoot, count));
	}

	private void printNode(final FsCollection fsCollection) throws FsException, FsException,
			IOException, FsException {

		for (final Waypoint waypoint : fsCollection.getChildReferences()) {
			FsCollection child = fsCollection.getCollection(waypoint.getId());
			if (waypoint.isLeaf()) {
				printLeaf(child, System.out);
			} else {
				printNode(child);
			}
		}
	}

}
